define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wdsxh/member_unit/index' + location.search,
                    add_url: 'wdsxh/member_unit/add',
                    edit_url: 'wdsxh/member_unit/edit',
                    del_url: 'wdsxh/member_unit/del',
                    multi_url: 'wdsxh/member_unit/multi',
                    import_url: 'wdsxh/member_unit/import',
                    table: 'wdsxh_member_unit',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'cat.name', title: __('行业分类')},
                        {field: 'level.name', title: __('商会级别')},
                        {field: 'member.name', title: __('会员代表')},
                        {field: 'company_name', title: __('Company_name'), operate: 'LIKE'},
                        {field: 'company_logo', title: __('Company_logo'), operate: 'LIKE',events: Table.api.events.image,formatter: Table.api.formatter.image},
                        {field: 'company_principal', title: __('Company_principal'), operate: 'LIKE'},
                        {field: 'company_post', title: __('Company_post'), operate: 'LIKE'},
                        {field: 'company_mobile', title: __('Company_mobile'), operate: 'LIKE'},
                        {
                            field: 'company_address',
                            title: __('Company_address'),
                            operate: 'LIKE',
                            formatter: function (value,row,index) {
                                return row.company_address + ' ' + row.company_address_detail;
                            }
                        },
                        {field: 'company_site', title: __('Company_site'), operate: 'LIKE'},
                        {field: 'company_email', title: __('Company_email'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        shop_add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        shop_edit: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});